using HDLogCenter.Dal.Repos;
using HDLogCenter.Infrastructure.Models;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace HDLogCenter.Bll.Services
{
    public class AlertRuleService
    {
        private readonly AlertRuleRepo _alertRuleRepo;

        public AlertRuleService(AlertRuleRepo alertRuleRepo)
        {
            _alertRuleRepo = alertRuleRepo;
        }

        public async Task<IEnumerable<AlertRuleModel>> GetAllAlertRulesAsync()
        {
            return await _alertRuleRepo.GetAllAsync();
        }

        public async Task<AlertRuleModel> GetAlertRuleByIdAsync(long id)
        {
            return await _alertRuleRepo.GetByIdAsync(id);
        }

        public async Task<IEnumerable<AlertRuleModel>> GetAlertRulesByAppCodeAsync(string appCode)
        {
            return await _alertRuleRepo.GetByAppCodeAsync(appCode);
        }

        public async Task<long> CreateAlertRuleAsync(AlertRuleModel alertRule)
        {
            var result = await _alertRuleRepo.CreateAsync(alertRule);
            return result ?? 0;
        }

        public async Task<bool> UpdateAlertRuleAsync(AlertRuleModel alertRule)
        {
            return await _alertRuleRepo.UpdateAsync(alertRule);
        }

        public async Task<bool> DeleteAlertRuleAsync(long id)
        {
            return await _alertRuleRepo.DeleteAsync(id);
        }
    }
}